package com.kingwood.algorithm.test;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * @Author 22025812
 * @Description: TODO
 * @Date: 2024/2/26 16:48
 * @Modified By：
 * @Version 1.0
 */
public class Common {
    /**
     * 最大座位数
     * 在一个大型体育场内举办了一场大型活动，由于疫情防控的需要，要求每位观众的必须间隔至少一个空位才允许落座。
     * 现在给出一排观众座位分布图，座位中存在已落座的观众，请计算出，在不移动现有观众座位的情况下，最多还能坐下多少名观众。
     */
    public static int getMaxSeatNum(char[] seats) {
        int maxSeatNum = 0;
        for (int i = 0; i < seats.length; i++) {
            if (seats[i] == '0') {
                boolean leftIsEmpty = i == 0 || seats[i - 1] == '0';
                boolean rightIsEmpty = i == seats.length -1 || seats[i + 1] == '0';
                if (leftIsEmpty && rightIsEmpty) {
                    seats[i] = '1';
                    maxSeatNum++;
                    i++;
                }
            }
        }

        return maxSeatNum;
    }

    public static String checkPassword(String str) {
        LinkedList<Character> stack = new LinkedList();
        for (int i=0; i<str.length(); i++) {
            char c = str.charAt(i);
            if (c == '<') {
                if(stack.isEmpty()) {
                    continue;
                }
                stack.removeLast();
            } else {
                stack.add(c);
            }
        }

        int uppper = 0;
        int lower = 0;
        int number = 0;
        int non_letter_number = 0;
        StringBuilder passwd = new StringBuilder();

        for (Character c : stack) {
            passwd.append(c);

            if (Character.isUpperCase(c)) {
                uppper++;
            } else if (Character.isLowerCase(c)) {
                lower++;
            } else if (Character.isDigit(c)) {
                number++;
            } else {
                non_letter_number++;
            }
        }
        if (passwd.length() >= 8 && uppper >= 1 && lower >= 1 && number >= 1 && non_letter_number >= 1) {
            passwd.append(",true");
        } else {
            passwd.append(",false");

        }

        return passwd.toString();
    }

    /**
     * 分割均衡字符串
     * https://blog.csdn.net/qfc_128220/article/details/134346347
     *
     * @param str
     * @return
     */
    public static int getBalanceSubStrCount(String str) {
        int count = 0;
        int countX = 0;
        int countY = 0;
        int len = str.length();
        for (int i = 0; i < len; i++) {
            if (str.charAt(i) == 'X') {
                countX++;
            } else {
                countY++;
            }

            if (countX == countY) {
                count++;
            }
        }

        return count;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
//        char[] seats = scanner.next().toCharArray();
//        int maxSeatNum = getMaxSeatNum(seats);
//        System.out.println(maxSeatNum);
//        String password = scanner.nextLine();
//        System.out.println(checkPassword(password));

        String str = scanner.nextLine();
        System.out.println(getBalanceSubStrCount(str));
    }
}
